package com.hspedu.furns.dao.impl;

import com.hspedu.furns.dao.BasicDAO;
import com.hspedu.furns.dao.OrderDAO;
import com.hspedu.furns.entity.Order;

import java.util.List;

/**
 * @author 徐
 * @version 1.0
 */
public class OrderDAOImpl extends BasicDAO<Order> implements OrderDAO {
    /**
     * 添加订单信息到数据库
     * @param order
     * @return
     */
    @Override
    public int saveOrder(Order order) {
        String sql = "INSERT INTO `order`(`id`,`create_time`,`price`,`status`,`member_id`)\n" +
                "VALUES(?,?,?,?,?)";
        return update(sql,order.getId(),order.getCreateTime(),
                order.getPrice(),order.getStatus(),order.getMemberId());
    }

    /**
     * 根据订单id查询订单
     * @param id
     * @return 不为null，返回order对象
     */
    @Override
    public Order showOrder(String id) {
        String sql = "SELECT `id`,`create_time` createTime ,`price`,`status`,`member_id` memberId FROM `order`\n" +
                "WHERE `id` = ?";
        return querySingle(sql,Order.class,id);
    }

    /**
     * 查询所有订单记录，用于展示
     * @return
     */
    @Override
    public List<Order> queryOrders() {
        String sql = "SELECT `id`,`create_time` createTime ,`price`,`status`,`member_id` memberId FROM `order`";
        return queryMulti(sql,Order.class);
    }
}
